import {ref} from 'vue'
import axios  from 'axios'
export function getAnimal<T>(url: string) {
    let result = ref<T|null>(null);
    let error = ref("")
    let loading = ref(true); //加载中状态
    let loaded = ref(false); //加载完毕
    axios.get(url).then(res => {
        loading.value = false //停止加载中状态
        loaded.value = true; //加载完毕
        result.value = res.data;
        console.log(res.data)
    }).catch(err => {
        error.value = err;
        loaded.value = true;
    })
    return {
        result,
        error,
        loaded
    }
}